package util;

import java.io.IOException;

public class HideProcess {
    public static void hideApplicationByProcessId(int processId) {
        String script = String.format("tell application \"System Events\" to set visible of application process id %d to false", processId);

        try {
            Process osascript = Runtime.getRuntime().exec(new String[]{"osascript", "-e", script});
            int result = osascript.waitFor();
            if (result == 0) {
                System.out.println("Process with PID " + processId + " has been hidden.");
            } else {
                System.err.println("Failed to hide process with PID " + processId);
            }
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
            System.err.println("Failed to hide process with PID " + processId);
        }
    }
}